﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DBUtility;
using Model;
using MySql.Data.MySqlClient;

namespace DAL
{
    public class AccessTokenDAL
    {
        public AccessTokenDAL()
        {
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int AddAccessToken(accesstoken model)
        {
            MySqlParameter[] para = {
                new MySqlParameter("@access_token",model.access_token),
                new MySqlParameter("@expires_in",model.expires_in),
                new MySqlParameter("@timestamp",model.timestamp),
                new MySqlParameter("@type",model.type)
            };
            return DBUtility.MySqlHelper.ExecuteNonQuery("INSERT INTO accesstoken (`access_token`,`expires_in`,`timestamp`,`type`) VALUES(@access_token,@expires_in,@timestamp,@type)",para);
        }

        

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int UpdateAccessToken(accesstoken model)
        {
            MySqlParameter[] para = {
                new MySqlParameter("@access_token",model.access_token),
                new MySqlParameter("@expires_in",model.expires_in),
                new MySqlParameter("@timestamp",model.timestamp),
                new MySqlParameter("@type",model.type)
            };
            return DBUtility.MySqlHelper.ExecuteNonQuery("UPDATE accesstoken SET `access_token`=@access_token,`expires_in`=@expires_in,`timestamp`=@timestamp WHERE `type`=@type", para);
        }

        /// <summary>
        /// 获取一条
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static accesstoken GetModel(string type)
        {
            return DBUtility.MySqlHelper.ExecuteDataReaderModel<accesstoken>("select * from accesstoken where `type`=@type",new MySqlParameter("@type",type));
        }

    }
}
